package com.oa.demo.server.system.configure;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;

/**
 * @author 孔德成
 * @date 2020/11/23 14:30
 */
@Configuration
@EnableResourceServer
public class OaResourceServerConfigurerAdapter extends ResourceServerConfigurerAdapter {

    public OaResourceServerConfigurerAdapter() {
        super();
    }

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
        super.configure(resources);
    }

    /**
     *
     * @param http 相当于xml文件中的http拦截配置
     * @throws Exception
     */
    @Override
    public void configure(HttpSecurity http) throws Exception {
        //所有访问oa-server-system的请求都需要认证，只有通过认证服务器发放的令牌才能进行访问
        http.csrf().disable()
                .requestMatchers().antMatchers("/**")
                .and()
                .authorizeRequests().antMatchers("/**").authenticated();
    }
}
